'use strict';

const conn = require('../../../libs/Conn');

module.exports = async function (params) {
    let checkUserGroupSql = `SELECT ug.group_name FROM user_group ug  WHERE ug.group_name = ? AND ug.delete_sign = 1`;
    let repeatData = (await conn(checkUserGroupSql, [params.group_name])).shift();
    if (repeatData) {
        let repeat = `用户组名称重复`;
        return {success: false, message: repeat};
    } else {
        let insertObj = {
            group_name: params.group_name,
            sys_menu_id: params.sys_menu_id,
            sys_button_id: params.sys_button_id,
            department:params.department_id
        };
        let insertSql = `insert into user_group set ?`;
        await conn(insertSql, [insertObj]);
        return {success: true};
    }
};